🛡️

Cybersecurity Lab

Due date for Labs submission - November 29, 2025 via Omnivox's Lea !

Lab Environment (Reference)

Subnet: 10.0.2.0/24
Router VM

Xubuntu Router

  • WAN (Internet): enp0s3
  • LAN (Gateway): enp0s8
  • IP Address: 10.0.2.1
Client VM

Client Machine

  • Interface: eth0
  • Gateway: 10.0.2.1
  • IP Address: 10.0.2.100

How to solve these challenges:

  • Write your solution as root (`sudo su`) on the Router VM terminal.
  • You can run commands directly or create a shell script (e.g., `nano task1.sh`, `chmod +x task1.sh`, `./task1.sh`).
  • If you get an error, read the message, refine your command, and try again.

Part 1: The Iptables Command

Challenge #1: Default Policies

filter table

Write the iptables commands that set the default POLICY to ACCEPT on INPUT and OUTPUT chains and DROP on FORWARD chain.

Challenge #2: Listing Rules

filter table

Write the iptables command that lists only the filter table of the INPUT chain.

Challenge #3: The NAT Table

nat table

Write the iptables commands that list the nat table.

Challenge #4: Flushing

filter table

Write the iptables command that flushes the filter table of all chains.

Challenge #5: Dropping Specific Traffic

INPUT chain

Write an iptables rule that drops all incoming packets to port 22/tcp (ssh). This should be the first rule in the chain.

Challenge #6: Reset / Delete Firewall

Dangerous

Write the iptables commands that flush all the tables of all chains and set the ACCEPT policy on all chains. This will delete any firewall configuration.

Part 2: Basic Matches

Challenge #1: Filter by IP

INPUT/OUTPUT

Write the iptables rules that drop all incoming packets from 100.0.0.1 and 1.2.3.4 and all outgoing packets to 80.0.0.1. These must be the first rules in the chains.

Challenge #2: Drop Specific Outgoing TCP

OUTPUT chain

Write the iptables rules that drop all outgoing generated packets of type TCP (port 80 and 443) to www.linuxquestions.org.

Challenge #3: Drop Routed Traffic

FORWARD chain

Write the iptables rules that drop all outgoing packets (routed through this machine) of type TCP (port 80 and 443) to www.linuxquestions.org.

Challenge #4: Drop Subnet

INPUT chain

Write an iptables rule that drops all incoming packets from network 27.103.0.0/16 (Netmask 255.255.0.0). This must be the first rule in the chain.

Challenge #5: Enforce DNS Server

FORWARD chain

The DNS Server of your LAN is set to 8.8.8.8. You don't want to allow LAN users to change this. Write a rule to drop all UDP packets to port 53 (DNS) if they are destined to any IP address other than 8.8.8.8.

Challenge #6: Allow Loopback

lo interface

Write the iptables rules that allow all traffic on the loopback (lo) interface (both incoming and outgoing).

Challenge #7: Interface Specific SSH

FORWARD chain

Your Linux Machine is the router.

Note for Lab: The internal LAN interface is enp0s8 and the external WAN interface is enp0s3.

Write the iptables rules that allow establishing routed incoming SSH (tcp/22) connections only from the LAN. Drop SSH connections coming from the WAN.

Part 3: Advanced Matches

Challenge #1: Help Commands

man pages

Run the iptables commands that list the help of: a) time match, b) mac match, c) limit match.

Challenge #2: Stateful Firewall (Basic)

INPUT/OUTPUT

Create a firewall script for your Laptop (runs Linux). All outgoing traffic is allowed, but only the return incoming traffic is permitted. No services are running on the laptop (Drop everything else).

Challenge #3: Stateful Firewall (Complete)

Security Baseline

Consider Challenge #2. Enhance your script to also:

  • Allow loopback interface traffic
  • Drop INVALID packets explicitly
  • Flush the firewall at the start

Challenge #4: Trusted Source SSH

INPUT chain

Consider Challenge #3. You start an SSH Daemon on your laptop. Add a rule to allow incoming SSH connections (tcp/22) only from your work (IP address: 100.0.0.1).

Challenge #5: MAC Filtering (Router Only)

MAC Match

The Router's MAC Address is b4:6d:83:77:85:f5. Write a single rule that allows communication only with the router. Drop packets from any other host in the LAN. Do not modify the policy.

Challenge #6: MAC Whitelist Script

Bash Loop

You have a server and 5 trusted hosts with MACs ending in f1 through f5. Write a script that allows only these 5 hosts to communicate with the server.

Challenge #7: Time-Based Web Access

Time Match

Write rules permitting outgoing web traffic (TCP 80/443) only between 10:00 and 18:00 UTC.

Challenge #8: Weekend Access Only

Time + Weekdays

Modify Challenge #7 to allow web traffic only on the weekend (Sat, Sun) between 10:00 and 18:00 UTC.

Challenge #9: Limit Ping

Limit Match

Write rules that permit only 2 incoming ICMP echo-request (ping) packets per second from any IP address.

Challenge #10: Limit TCP Connections

Connlimit Match

Write a rule that permits only 10 NEW TCP connections from the same IP address.

Part 4: NAT & Port Forwarding

Challenge #1: Basic NAT Configuration

SNAT / Masquerade

Configure the Router VM to perform Network Address Translation (NAT) for the LAN network (10.0.2.0/24).

1. Flush the NAT table.
2. Enable IP Forwarding.
3. Apply SNAT for the entire subnet going out the external interface (enp0s3). Assume the public IP is 80.0.0.1.
(Bonus: What target would you use if the IP was dynamic?)

Challenge #2: Port Forwarding (DNAT)

DNAT / PREROUTING

You have a Web Server running inside the LAN at 192.168.0.20 on port 80.
Configure the router so that all packets coming to the Router's public IP on port 80 are forwarded to the internal server.

Variants: Also redirect external port 8080 to the internal server's port 80.